package address

import (
	"gitee.com/xgotool/backend-framework-template/config"
	"gitee.com/xgotool/backend-framework-template/model"
)

// 地址列表
// 因用户的地址不会过多，所以此列表未进行分页操作
//
//	uid	用户ID
func List(uid uint) ([]model.Address, error) {
	mod, mods := model.Address{}, []model.Address{}
	conn, err := config.GetConnect()
	if err != nil {
		return nil, err
	}
	err = conn.Table(mod.TableName()).
		Where("uid", uid).
		Where("is_deleted", 0).
		Omit("is_deleted", "uid", "updated_at").
		Order("is_default DESC, id ASC").
		Find(&mods).
		Error
	if err != nil {
		return nil, err
	}
	return mods, nil
}
